package com.ctshk.rpc.system.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ctshk.rpc.system.base.CustomBaseMapper;
import com.ctshk.rpc.system.dto.StockScenicAreaPhotoDTO;
import com.ctshk.rpc.system.dto.StockScenicQueryAreaPhotoDTO;
import com.ctshk.rpc.system.entity.StockScenicAreaPhoto;
import com.ctshk.rpc.system.req.StockScenicAreaPhotoListReq;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 *
 * </p>
 *
 * @author xuhui
 * @since 1/29/2021
 */
public interface StockScenicAreaPhotoMapper extends CustomBaseMapper<StockScenicAreaPhoto> {


    /**
     * 根据地区id或名称查询图片
     *
     * @param stockScenicAreaPhotoListReq
     * @param page
     * @return
     */
    @Select("<script>" + "select p.file_type fileType, p.id id,p.stock_id stockId,p.title title,p.files files from t_stock_scenic_area_photo p left join t_stock_scenic_area a on p.stock_id = a.id  WHERE 1=1 and p.is_deleted = 0\n" +
            "<if test=\"req.title != null\"> AND p.title like  CONCAT('%',#{req.title},'%') </if> \n" +
            "<if test=\"req.areaId != null\"> AND a.area_id = #{req.areaId}</if> \n" +
            "<if test=\"req.areaName != null\"> AND a.area_name = #{req.areaName}</if> \n" +
            "<if test=\"req.fileType != null\"> AND p.file_type = #{req.fileType}</if> \n" + "</script>"
    )
    IPage<StockScenicAreaPhotoDTO> queryList(@Param("req") StockScenicAreaPhotoListReq stockScenicAreaPhotoListReq, IPage<StockScenicAreaPhotoDTO> page);

    /**
     * 根据地区id或名称查询图片
     *
     * @param stockScenicAreaPhotoListReq
     * @param page
     * @return
     */
    @Select("<script>" + "select t.id,t.area_name areaName,count(t1.id) photoNumber from t_stock_scenic_area t left join t_stock_scenic_area_photo t1 on t.id = t1.stock_id   WHERE t.is_deleted = 0 \n" +
            "<if test=\"req.areaId != null\"> AND t.area_id = #{req.areaId}</if> \n" +
            "<if test=\"req.areaName != null\"> AND t.area_name = #{req.areaName}</if> \n" + " group by t.area_id  </script>"
    )    IPage<StockScenicQueryAreaPhotoDTO> queryAreaPhotoList(@Param("req") StockScenicAreaPhotoListReq stockScenicAreaPhotoListReq, IPage<StockScenicQueryAreaPhotoDTO> page);
    
}